﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Entity;
using Core.Dao;
using System.Data;

namespace Core.Business
{
    public class UserTypeBus
    {
        private UserTypeDao dao;
        public UserTypeBus() {
            dao = new UserTypeDao();
        }

        public bool insert(UserType userType) {
            return dao.insert(userType);
        }

        public bool update(UserType userType) {
            return dao.update(userType);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public UserType get(int id) {
            DataTable dt = dao.get(id);
            UserType userType = new UserType();

            if (dt.Rows.Count > 0)
            {
                userType.Id = Convert.ToInt32(dt.Rows[0]["UST_ID"]);
                userType.Name = dt.Rows[0]["UST_NAME"].ToString();
                userType.Desc = dt.Rows[0]["UST_DESC"].ToString();
            }
            return userType;
        }

        public List<UserType> getAll() {
            DataTable dt = dao.getAll();
            List<UserType> list = new List<UserType>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    UserType userType = new UserType();
                    userType.Id = Convert.ToInt32(dr["UST_ID"]);
                    userType.Name = dr["UST_NAME"].ToString();
                    userType.Desc = dr["UST_DESC"].ToString();

                    list.Add(userType);
                }

            }
            return list;
        }
    }
}
